<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>编辑教师</title>
    <link rel="stylesheet/less" href="../../../static/css/index.less"/>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css"/>
    <link rel="stylesheet" href="../../../static/css/jquery.pagination.css"/>
    <script src="../../../static/js/jquery-1.12.3.js"></script>
    <script src="../../../static/js/ajaxfileupload.js"></script>
    <script src="../../../static/js/less.min.js"></script>
    <script src="../../../static/layui/layui.js"></script>
    <script src="../../../static/layer/layer.js"></script>
</head>
<style>
    .newadd {
        padding: 10px 0;
        display: block;
        text-align: left;
    }

    .newadd label .adtitle {
        display: inline-block;
        width: 6rem;
        text-align: right;
        padding-right: 2%;
    }

    .newadd input {
        padding: 0 10px;
        width: 20%;
        height: 30px;
        line-height: 30px;
        border: 1px solid #dcdcdc;
        border-radius: 5px;
    }

    .newadd select {
        border: 1px solid #dcdcdc;
        border-radius: 5px;
    }

    .button button {
        color: #fff;
        padding: 5px 10px;
        -webkit-border-radius: 3px;
        -moz-border-radius: 3px;
        border-radius: 3px;
    }

    .button button a {
        color: #fff;
    }
</style>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    {% include "admin/top.html" %}
    {% include "admin/left.html" %}
    <div class="layui-body">
        <div id="box" class="fl" style="width: 100%">
            <div class="content">
                <h3>编辑教师</h3>
                <div class="newadd">
                    <label for="">
                        <span class="adtitle">登陆账号</span>
                        <input readonly="readonly" type="text" value="{{ res.username | default('', true) }}" id="username">
                    </label>
                    <label for="">
                        <span class="adtitle">密码</span>
                        <input readonly="readonly" type="text" value="{{ res.password | default('', true) }}" id="password">
                        <button id="pw" class="subbtn">修改密码</button>
                    </label>

                    <label for="">
                        <span class="adtitle">昵称</span>
                        <input type="text" value="{{ res.nickName | default('', true) }}" id="nickname">
                    </label>
                    <label for="">
                        <span class="adtitle">手机号</span>
                        <input type="text" value="{{ res.phone | default('', true) }}" id="phone">
                    </label>

                    <label>
                        <span class="adtitle">教师头像</span>
                        {% if res.header %}
                        <img src="{{ res.header }}" style="width: 10rem;">
                        {% endif %}
                        <input type="file" name="file" id="xdaTanFileImg">
                    </label>

                    <label for="">
                        <span class="adtitle">个人签名</span>
                        <textarea id="info" style="min-width:708px;min-height:142px;">{{ res.info | default('', true) }}</textarea>
                    </label>

                    <label class="button" style="margin-left: 8rem;">
                        <button id="btn" class="subbtn">提交</button>

                        <button class="subbtn"><a href="javascript:window.history.go(-1)">返回</a></button>
                    </label>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script>
    $(":button").click(function(){
        $('#password').removeProp("readonly");
        $("#password").css("color","red");
});
    $("#btn").click(function () {
        var password = $('#password').val();
        var nickname = $('#nickname').val();
        var phone = $('#phone').val();
        var info = $('#info').val();
        var uid = "{{ res.uid }}";
{#        var q = checkpassword(password);#}
{#        if (!q){#}
{#            return false;#}
{#        }#}
        if (nickname == ''){
            layer.msg("昵称不能为空");
            return false;
        }
        $.ajaxFileUpload({
            url:"/admin/teacher_detail_post",
            type:"post",
            data:{
                'password':password,
                'nickname':nickname,
                'phone':phone,
                'info':info,
                'uid':uid
            },
            dataType:"json",
            secureuri: false, //是否需要安全协议，一般设置为false
            fileElementId: 'xdaTanFileImg', //文件上传域的ID
            success:function(msg){
                if (msg.status == 1){
                    layer.msg("操作成功", {time:1200}, function(){
                        location.href = document.referrer;
                    })
                }else if(msg.status == 2){
                    layer.msg("账号不存在");
                }
                else {
                    layer.msg("操作失败");
                }
            }
        })
    });

    checkpassword = function (v) {
        var numasc = 0;
        var charasc = 0;
        var otherasc = 0;
        if (0 == v.length) {
            layer.msg("密码不能为空");
            return false;
        } else if (v.length < 8 || v.length > 16) {
            layer.msg("密码至少8个字符,最多16个字符");
            return false;
        } else {
            for (var i = 0; i < v.length; i++) {
                var asciiNumber = v.substr(i, 1).charCodeAt();
                if (asciiNumber >= 48 && asciiNumber <= 57) {
                    numasc += 1;
                }
                if ((asciiNumber >= 65 && asciiNumber <= 90) || (asciiNumber >= 97 && asciiNumber <= 122)) {
                    charasc += 1;
                }
                if ((asciiNumber >= 33 && asciiNumber <= 47) || (asciiNumber >= 58 && asciiNumber <= 64) || (asciiNumber >= 91 && asciiNumber <= 96) || (asciiNumber >= 123 && asciiNumber <= 126)) {
                    otherasc += 1;
                }
            }
            if (0 == numasc) {
                layer.msg("密码必须含有数字");
                return false;
            } else if (0 == charasc) {
                layer.msg("密码必须含有字母");
                return false;
            } else if (0 == otherasc) {
                layer.msg("密码必须含有特殊字符");
                return false;
            } else {
                return true;
            }
        }
    };
</script>



